package mspdt.ubzuuch.mn;

import java.util.ArrayList;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;

public class GalleryAdapter extends BaseAdapter {

	private LayoutInflater mInflater;
	private ImageLoader imgLoader;
	private ArrayList<String> images;
	private Context context;

	public GalleryAdapter(Context context, ArrayList<String> images) {
		mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		this.images=images;
		this.context = context;
		imgLoader = new ImageLoader(context);
	}

	@Override
	public int getCount() {
		return images.size();
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.gallery_item, null);
		}
		ImageView image = (ImageView) convertView.findViewById(R.id.gallery_image);
		if(!images.get(position).equals("") && (images.get(position).endsWith(".png") || images.get(position).endsWith(".jpeg") || images.get(position).endsWith(".jpg")))
			imgLoader.DisplayImage(images.get(position), image);
		//((ImageView) convertView.findViewById(R.id.gallery_image)).setImageResource(images.get(position));
		
		return convertView;
	}
}

